package com.example.qxfw.qxybzz.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.util.WeatherInfoUtil;
import com.example.qxfw.qxybzz.entity.*;
import com.example.qxfw.qxybzz.service.MeteorologyMaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 气象服务材料制作
 *
 * @author 14559
 * @version 1.0
 * @description: TODO
 * @date 2024/12/11 16:59
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/meteorologyMater")
public class MeteorologyMaterialsController {

    @Autowired
    private MeteorologyMaterialsService materialsService;

    /***
     * 获取当前级别的服务材料模板
     * @param onetype 传行政区划：伊犁州、伊宁市
     * @return
     */
    @RequestMapping("/getJobModels")
    public SysResult getJobModels(String onetype) {
        List<jobmodel> list = materialsService.getJobModels(onetype);
        return SysResult.success(list);
    }

    /**
     * 获取当前模板的往期资料（含三个框的文字内容）
     *
     * @param onetype
     * @param twotype
     * @return
     */
    @RequestMapping("/getHistoryProduct")
    public SysResult getHistoryProduct(String onetype, String twotype) {
        List<SummaryProduct> list = materialsService.getHistoryProduct(onetype, twotype);
        return SysResult.success(list);
    }

    /***
     * 得到实况查询的各项数据：文字、统计、站点排名、国家站排名、气候特征统计一、图片
     * @param msg
     * @return
     */
    @RequestMapping("/getMsgAllData")
    @ResponseBody
    public SysResult getMsgAllData(@RequestBody msgparam msg) {
        ArrayList list = materialsService.getMsgAllData(msg);
        return SysResult.success(list);
    }

    /***
     * 得到单个站点的气候特征统计信息
     * @param msg
     * @return
     */
    @RequestMapping("/getMsgClimaticCharacteristicsData")
    @ResponseBody
    public SysResult getMsgClimaticCharacteristicsData(@RequestBody msgparam msg) {
        List<MeteorologyData> list = materialsService.getMsgClimaticCharacteristicsData(msg);
        return SysResult.success(list);
    }

    /***
     * 得到预报数据表格
     * @param param
     * @return
     */
    @RequestMapping("/getGridFcstData")
    @ResponseBody
    public SysResult getGridFcstData(@RequestBody gridfcstparam param) {
        Map<String, Object> arrayList = new HashMap<>();
        List<MeteorologyFcstData> list = materialsService.getGridFcstData(param);
        arrayList.put("ybdata", list);
        String ybContent = "预计：";
        for (MeteorologyFcstData data : list) {
            ybContent += data.getStationname() + "天气" + data.getWeather()
                    + "；温度" + data.getMintemp() + "~" + data.getMaxtemp() + "℃"
                    + "；风力" + WeatherInfoUtil.GetWeatherFs(String.valueOf(WeatherInfoUtil.fengSuToFengJi(data.getWind())))
                    + "、风向" + WeatherInfoUtil.getFX(data.getWind()) + "。";
        }
        arrayList.put("ybcontent", ybContent);
        return SysResult.success(arrayList);
    }

    /***
     * 得到措施建议
     * @return
     */
    @RequestMapping("/getJobStandard")
    @ResponseBody
    public SysResult getJobStandard() {
        List<job_standard> list = materialsService.getJobStandard();
        return SysResult.success(list);
    }


    /**
     * 新增措施建议
     * @return
     */
    @ResponseBody
    @PostMapping("/addJobStandard")
    public SysResult addJobStandard(@RequestParam("type")String type, @RequestParam("grading") String grading, @RequestParam("context") String context) {
        materialsService.addJobStandard(type, grading, context);
        return SysResult.success();
    }



    /***
     * 常规服务材料制作
     * @param jsonData json字符串
     * @param images 图片
     * @return
     */
    @RequestMapping("/makeCommonMaterialDoc")
    public Object makeCommonMaterialDoc(@RequestParam("jsonData") String jsonData, @RequestParam("images") MultipartFile[] images) {
        return materialsService.makeCommonMaterialDoc(jsonData, images);
    }
}
